package cn.xbtop.queue;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

/**
 * @author Mxb
 * @version 1.0
 * @date 2020/6/10 15:56
 */
public class TestQueueProducer {
    public static void main(String[] args) {
        ApplicationContext ap = new ClassPathXmlApplicationContext("application-queue.xml");
        //从ioc容器中得到jmsTemplate
        JmsTemplate jmsTemplate = ap.getBean(JmsTemplate.class);

        //发送消息
        jmsTemplate.send(new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                //创建消息
                TextMessage textMessage = session.createTextMessage("MQ-spring-queue");
                //设置flag 标签
                textMessage.setStringProperty("flag", "加急信件spring");
                return textMessage;

            }
        });
        System.out.println("消息发送完成----");
    }
}
